<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>04_JS的流程控制</title>
</head>
<body>
<script>
    //1.顺序结构
    console.log(1)
    console.log(2)
    console.log(3)

    //2.分支结构
    var age = 14
    if (age >= 18) {
        console.log('可以投票')
    } else {
        console.log('不可以投票')
    }

    let uname="";
    if (!uname){
        // alert("请输入用户名");
    }else{
        // alert("欢迎登录"+uname);
    }

    //3.选择分支
    let gender = 0 ;
    switch(gender){
        case 1:
        console.log("男")
            break;
        case 0:
        console.log("女")
            break;
        default:
        console.log("未知")
    }

    //4.循环结构
    let names = ["张三","威哥","阿威","威神"]
    for (var i=0;i<names.length;i++){
        console.log(names[i]);
    }
    console.log("循环结束");
    //如果用uar定义循环变量i,循环结束后在此处仍能打印出i的值
    //但如果使用let定义i，循环结束会报错：ReferenceError: i is not defined
    console.log(i);

    //5.增强for循环
    //n是每轮遍历从names数组中取出的元素
    for (let n of names){
        console.log(n);
    }

</script>
</body>
</html>